<?php
/**
 * Model for eqtech-hotelbooking Component
 * 
 * @package    eqtech-hotelbooking joomla
 * @subpackage Components
 * @link 
 * @license        GNU/GPL
 */
 
// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
/**
 *
 * @package    joomla eqtech-hotelbooking
 * @subpackage Components
 */
class HbControllerCrud extends HbController
{
	/**
	 * constructor (registers additional tasks to methods)
	 * @return void
	 */
	 
	public $controller_name='country';
	//public $table_name='hbtb_country';
	function __construct()
	{
		parent::__construct();
 
		// Register Extra tasks
		$this->registerTask( 'add'  , 	'edit' );
	}
 
	/**
	 * display the edit form
	 * @return void
	 */
	function edit()
	{
		$model = $this->getModel($this->controller_name);
		JRequest::setVar( 'view', $this->controller_name );
		JRequest::setVar( 'layout', 'form'  );
		JRequest::setVar('hidemainmenu', 1);
		$msg = JText::_( 'controller:country, task edit' );
		parent::display();
	}
	
	function editList()
	{
		$model = $this->getModel($this->controller_name);
		JRequest::setVar( 'view', 'country' );
		JRequest::setVar( 'layout', 'default'  );
		JRequest::setVar('hidemainmenu', 1);
		$msg = JText::_( 'controller:country, task editList' );
		//parent::display();
		HbViewCountry::displayList();
	}
	
	/**
	 * save a record (and redirect to main page)
	 * @return void
	 */
	function save()
	{
		$model = $this->getModel($this->controller_name);
		
		if ($model->store()) {
			$msg = JText::_( 'Country Record Saved!' );
		} else {
			$msg = JText::_( 'Error Saving Country Record' );
		}
	 
		//Check the table in so it can be edited.... we are done with it anyway
		$link = 'index.php?option=com_hb&view=countries';
		$this->setRedirect($link, $msg);
		
	}
	
	
	
/**
 * remove record(s)
 * @return void
 */
function remove()
{
    $model = $this->getModel($this->controller_name);
    if(!$model->delete()) {
        $msg = JText::_( 'Error: One or More Country Record Could not be Deleted' );
    } else {
        $msg = JText::_( 'Country Record(s) Deleted' );
    }
 $link = 'index.php?option=com_hb&view=countries';
		$this->setRedirect($link, $msg);
}

}
